#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import os
from sklearn.cluster import KMeans
from sklearn.metrics import accuracy_score

# read data
homePath = "data"
trainPath = os.path.join(homePath, "train.csv")
testPath = os.path.join(homePath, "test.csv")
submitPath = os.path.join(homePath, "sample_submit.csv")
trainData = pd.read_csv(trainPath)
testData = pd.read_csv(testPath)
submitData = pd.read_csv(submitPath)

# 去掉没有意义的一列
trainData.drop("CaseId", axis=1, inplace=True)
testData.drop("CaseId", axis=1, inplace=True)
y = trainData['Evaluation']
trainData.drop("Evaluation", axis=1, inplace=True)

# do k-means
est = KMeans(n_clusters=2, init="k-means++", n_jobs=-1)
est.fit(trainData, y)
y_train = est.predict(trainData)
y_pred = est.predict(testData)

# 保存预测的结果
submitData['Evaluation'] = y_pred
submitData.to_csv("submit_data.csv", index=False)

# calculate accuracy
acc_train = accuracy_score(y, y_train)
print("acc_train = %f" % (acc_train))




